package com.eureka.h;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@EnableWebSecurity
@Configuration
public class WebSecurityConfig {

    @Bean
    public WebSecurityConfigurerAdapter filterChain() throws Exception {
        return new WebSecurityConfigurerAdapter() {
            protected void configure(HttpSecurity http) throws Exception {

//                http.csrf().disable()
//                        // 其他配置...
//                        .authorizeRequests()
//                        .requestMatchers(new AntPathRequestMatcher("/demo", "POST"))  // 使用RequestMatcher自定义规则
//                        .permitAll()
//                        .anyRequest().authenticated();
                http.authorizeRequests()
                        .antMatchers("/demo","/demo**","/demo/**").permitAll()
                        .anyRequest().authenticated()
                        .and()
                        .csrf().disable();
                super.configure(http);
            }
        };
    }
}
